package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysUsers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysBrowsingHistoryMapper;
import com.ruoyi.system.domain.SysBrowsingHistory;
import com.ruoyi.system.service.ISysBrowsingHistoryService;

/**
 * 浏览历史Service业务层处理
 *
 * @author ruoyi
 * @date 2024-03-01
 */
@Service
public class SysBrowsingHistoryServiceImpl implements ISysBrowsingHistoryService
{
    @Autowired
    private SysBrowsingHistoryMapper sysBrowsingHistoryMapper;

    /**
     * 查询浏览历史
     *
     * @param historyId 浏览历史主键
     * @return 浏览历史
     */
    @Override
    public SysBrowsingHistory selectSysBrowsingHistoryByHistoryId(Long historyId)
    {
        return sysBrowsingHistoryMapper.selectSysBrowsingHistoryByHistoryId(historyId);
    }

    /**
     * 查询浏览历史列表
     *
     * @param sysBrowsingHistory 浏览历史
     * @return 浏览历史
     */
    @Override
    public List<SysBrowsingHistory> selectSysBrowsingHistoryList(SysBrowsingHistory sysBrowsingHistory)
    {
        return sysBrowsingHistoryMapper.selectSysBrowsingHistoryList(sysBrowsingHistory);
    }

    /**
     * 新增浏览历史
     *
     * @param sysBrowsingHistory 浏览历史
     * @return 结果
     */
    @Override
    public int insertSysBrowsingHistory(SysBrowsingHistory sysBrowsingHistory)
    {
        return sysBrowsingHistoryMapper.insertSysBrowsingHistory(sysBrowsingHistory);
    }


    public void insertSysBrowsingHistory(SysUsers sysUsers)
    {
        List<SysBrowsingHistory> sysBrowsingHistoryList = sysUsers.getSysBrowsingHistoryList();
        Long userId = sysUsers.getUserId();
        if (StringUtils.isNotNull(sysBrowsingHistoryList))
        {
            List<SysBrowsingHistory> list = new ArrayList<SysBrowsingHistory>();
            for (SysBrowsingHistory sysBrowsingHistory : sysBrowsingHistoryList)
            {
                sysBrowsingHistory.setUserId(userId);
                list.add(sysBrowsingHistory);
            }
            if (list.size() > 0)
            {
                sysBrowsingHistoryMapper.batchSysBrowsingHistory(list);
            }
        }
    }























    /**
     * 修改浏览历史
     *
     * @param sysBrowsingHistory 浏览历史
     * @return 结果
     */
    @Override
    public int updateSysBrowsingHistory(SysBrowsingHistory sysBrowsingHistory)
    {
        return sysBrowsingHistoryMapper.updateSysBrowsingHistory(sysBrowsingHistory);
    }

    /**
     * 批量删除浏览历史
     *
     * @param historyIds 需要删除的浏览历史主键
     * @return 结果
     */
    @Override
    public int deleteSysBrowsingHistoryByHistoryIds(Long[] historyIds)
    {
        return sysBrowsingHistoryMapper.deleteSysBrowsingHistoryByHistoryIds(historyIds);
    }

    /**
     * 删除浏览历史信息
     *
     * @param historyId 浏览历史主键
     * @return 结果
     */
    @Override
    public int deleteSysBrowsingHistoryByHistoryId(Long historyId)
    {
        return sysBrowsingHistoryMapper.deleteSysBrowsingHistoryByHistoryId(historyId);
    }
}
